//
//  MySelfViewController.m
//  DaiShengInvest
//
//  Created by 张睿 on 2017/6/27.
//  Copyright © 2017年 davinci. All rights reserved.
//

#import "MySelfViewController.h"
#import "MyselfView.h"
#import "MySelfTableViewCell.h"
#import "MyAccountViewController.h"

@interface MySelfViewController ()<UITableViewDelegate,UITableViewDataSource>

@property (nonatomic, weak)UIImageView * backImage;

@property (nonatomic, strong)MyselfView * myView;

@property (nonatomic, strong)UITableView * tableView;

@property (nonatomic, strong)NSArray * imageNameArray;

@property (nonatomic, strong)NSArray * showStringArray;

@end

@implementation MySelfViewController


- (void)viewWillAppear:(BOOL)animated{
    
    
    
}



- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    _showStringArray = @[@"账户",@"推广赚钱",@"我的收益",@"联系客服",@"新闻资讯",@"关于DCM",@"系统设置"];
    _imageNameArray = @[@"账户",@"推广赚钱",@"我的收益",@"联系客服",@"新闻资讯",@"d",@"设置资料"];
    [self setupNavBar];
    [self setupUI];
//    [self setupTableView];
}


- (void)setupNavBar{
    
    UIButton * backButton = [[UIButton alloc] init];
    
    backButton.frame = CGRectMake(0 * SCREENH6, 0 * SCREENH6, 22 * SCREENH6, 25 * SCREENH6);
    [backButton setImage:[UIImage imageNamed:@"消息"] forState:UIControlStateNormal];

    [backButton addTarget:self action:@selector(pushToSystemMessage) forControlEvents:UIControlEventTouchUpInside];
    
    UIBarButtonItem * leftButton = [[UIBarButtonItem alloc] initWithCustomView:backButton];
    
    self.navigationItem.rightBarButtonItem = leftButton;
}



- (void)setupUI{
    
    UIImageView * backImage = [[UIImageView alloc] initWithFrame:self.view.bounds];
    
    backImage.image = [UIImage imageNamed:@"背景"];
    backImage.userInteractionEnabled = YES;
    
    self.backImage = backImage;
    
    [self.view addSubview:self.backImage];
    
    self.myView = [[MyselfView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 143 * SCREENH6)];
    
    
    [self.backImage addSubview:self.myView];
    
    
    self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 207 * SCREENH6, SCREEN_WIDTH, SCREENH_HEIGHT - 143 * SCREENH6)];
    
    self.tableView.delegate = self;
    self.tableView.dataSource = self;

    self.tableView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"背景"]];
    
    self.tableView.separatorColor = [UIColor grayColor];
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleSingleLine;
    self.tableView.bounces = NO;
    
    [self.tableView registerClass:[MySelfTableViewCell class] forCellReuseIdentifier:@"myselfCell"];
    
    [self.backImage addSubview:self.tableView];
}



- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    
    return 1;
}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    return 7;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    MySelfTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"myselfCell" forIndexPath:indexPath];
    
    cell.explationLabel.text = self.showStringArray[indexPath.row];
    cell.iconImage.image = [UIImage imageNamed:self.imageNameArray[indexPath.row]];

    
    return cell;
}


- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    if (indexPath.row == 0) {
        
        return 65 * SCREENH6;
        
    }else{
        
        return 58 * SCREENH6;
    }
    
    
}


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    self.hidesBottomBarWhenPushed = YES;
    
    if (indexPath.row == 0) {
        
        MyAccountViewController * myAccount = [MyAccountViewController new];
        
        [self.navigationController pushViewController:myAccount animated:YES];
        
    }
    
    
    
    self.hidesBottomBarWhenPushed = NO;
}


//跳转到系统消息
- (void)pushToSystemMessage{
    
    
    
    
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
